﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using Microsoft.Win32;

namespace csvformater.fileProcess
{
    /// <summary>
    /// FileOpenDialog.xaml 的交互逻辑
    /// </summary>
    public partial class FileOpenDialog : UserControl
    {
        private Microsoft.Win32.OpenFileDialog _fileOpen;
        public FileOpenDialog()
        {
            InitializeComponent();
            InitialingFileDialog();
        }

        private void InitialingFileDialog(bool multiSelect = false, string filter = "", bool restoreDir = true)
        {
            _fileOpen = new OpenFileDialog();
            _fileOpen.Multiselect = multiSelect;
            _fileOpen.RestoreDirectory = restoreDir;
        }

        /// <summary>
        /// get path value from FileOpenDialog 
        /// </summary>
        /// <returns></returns>
        public string GetPath()
        {
            return filePath.Text;
        }

        private void OpenFileClick(object sender, RoutedEventArgs e)
        {
            if((bool)(_fileOpen.ShowDialog()))
            {
                try
                {
                    filePath.Text = _fileOpen.FileName;
                }
                catch (Exception)
                {
                    throw new Exception(String.Format("Fail to open file : {0} ", _fileOpen.FileName));
                }
            }
        }
        
    }
}